package logic

import (
	"context"
	"product-mall/productrpc/productrpcclient"

	"product-mall/api/internal/svc"
	"product-mall/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type BrowseProductLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewBrowseProductLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BrowseProductLogic {
	return &BrowseProductLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BrowseProductLogic) BrowseProduct(req *types.BrowseProductRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	browse20, err := l.svcCtx.ProductRpc.BrowseProduct(l.ctx, &productrpcclient.BrowseProductRequest{})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Code:    500,
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Message: "商品浏览量前20展示成功",
		Code:    200,
		Data:    browse20,
	}, nil
}
